# coding: UTF-8
# ----------
# Project_Name : pythonProject
# File_Name : huangcongbing
# Author : asus
# Date_Time:2022/4/25 14:32
# Description :
# ----------
import unittest
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

class IndexPage(unittest.TestCase):
    """
    定义百度首页
    """
    #定义属性
    def __init__ (self,driver,wait):
        #    获取从用例层传入的driver和wait
        self.driver = driver
        self.wait = wait

        #调试使用
        # self.driver = webdriver.Chrome()
        # self.wait = WebDriverWait(self.driver,30)

        #对操作元素及定位封装
        self.search_box_locator = (By.ID,'kw')#搜索输入框定位符
        self.search_btn_locator = (By.ID,'su')#百度一下按键定位符
        self.setting_btn_locator = (By.ID,'s-usersetting-top')  #设置按键定位符
        self.top_login_btn_locator =(By.ID, 's-top-loginbtn')  #登陆按键定位符
        self.user_input_locator =(By.ID,'TANGRAM__PSP_11__userName')   #账号输入框定位符
        self.pwd_input_locator = (By.ID,'TANGRAM__PSP_11__password')   #密码输入框定位符
        self.logi_btn_locator = (By.ID,'TANGRAM__PSP_11__submit')     #登录按键定位符



    #定义方法
    def input_search_box(self,text):
        """
        输入搜索输入框
        :return:
        """
        self.wait.until(expected_conditions.visibility_of_element_located((self.search_box_locator)))
        el = self.driver.find_element(*self.search_box_locator)
        el.clear()
        el.send_keys(text)

    def click_search_button(self):
        """
        点击搜索按键
        :return:
        """
        self.wait.until(expected_conditions.visibility_of_element_located((self.search_box_locator)))
        el = self.driver.find_element(*self.search_box_locator)
        el.click()

    def move_to_settings(self):
        """
        一定鼠标到设置
        :return:
        """
        self.wait.until(expected_conditions.visibility_of_element_located((self.setting_btn_locator)))
        el = self.driver.find_element(*self.setting_btn_locator)
        ActionChains(self.driver).move_to_element(el).perform()


    def click_top_login_button(self):
        """
        点击登录按键
        :return:
        """
        self.wait.until(expected_conditions.visibility_of_element_located((self.top_login_btn_locator)))
        el = self.driver.find_element(*self.top_login_btn_locator)
        el.click()

    def input_user(self,username):   #输入账号
        self.wait.until(expected_conditions.visibility_of_element_located((self.user_input_locator)))
        el = self.driver.find_element(*self.user_input_locator)
        el.send_keys(username)

    def input_pwd(self,password):    #输入密码
        self.wait.until(expected_conditions.visibility_of_element_located((self.pwd_input_locator)))
        el = self.driver.find_element(*self.pwd_input_locator)
        el.send_keys(password)

    def click_login(self):   #点击登录
        self.wait.until(expected_conditions.visibility_of_element_located((self.logi_btn_locator)))
        el = self.driver.find_element(*self.logi_btn_locator)
        el.click()



